package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);not null;unique;comment:账号"`
	Password string `gorm:"type:char(32);not null;comment:密码"`
}

type UserIdentity struct {
	gorm.Model
	Realname string `gorm:"type:varchar(20);not null;index;comment:真实姓名"`
	IdCard   string `gorm:"type:char(18);not null;unique;comment:身份证号"`
	UserId   int64  `gorm:"type:int(11);not null;comment:用户ID"`
}

func (u *User) Register() error {
	return DB.Debug().Create(&u).Error
}

func (u *User) GetUserByMobile() error {
	return DB.Debug().Where("mobile = ?", u.Mobile).Find(&u).Error
}

func (i *UserIdentity) GetRealnameByUserId() error {
	return DB.Debug().Where("user_id = ?", i.UserId).Limit(1).Find(&i).Error
}

func (i *UserIdentity) Create() error {
	return DB.Debug().Create(&i).Error
}
